<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function _initialize()
    {   //检测当前访问的是哪个 模板 控制器 方法名
        $paths = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;

        //C函数读取Conf里的AUTH_PATHS
        //var_dump(C('AUTH_PATHS'));
        /*array (size=2)
          0 => string 'Home/Set/index'
          1 => string 'Home/jie/add'*/
        //var_dump($paths); //'Home/Set/index'

        //in_array — 检查数组中是否存在某个值 检测C('AUTH_PATHS')数组里面有没$paths项 如果$paths 是字符串，则比较是区分大小写的
        if (in_array($paths,C('AUTH_PATHS'))) {
            //isset — 检测变量是否设置
            if(!isset($_SESSION['id'])){
                $this->error('请先登录',U('home/login/index'));
                //var_dump('有限制');
            }/*else{
                $this->error('请先登录',U('home/login/index'));
                //var_dump('有限制');
            }*/

        }/*else{
            var_dump('没限制');
        }*/
    }



	//调用时传递的-数据库表名 -需要修改表里面的字段名 -修改的参数+1 -修改的id
    public function autoAdd($table,$filed,$num,$id){
    	//mysql> UPDATE stu SET name = '大牛学院' WHERE id = 1 ;
       $sql = "update ".$table." set ".$filed ."=".$filed.$num." where id='{$id}'";
       //var_dump($sql);
       M()->execute($sql);  //execute执行发送操作sql(针对UPDATE,DELETE,INSERT)
    }

    public function getTopView()
    {
    	//M('question')->order("order by view_num desc")->limit(6)->select();
    	$sql = "select * from question order by view_num desc limit 10";
    	//return M()->query($sql);
    	
    	$hotView = M()->query($sql);

    	$this->assign('hotView',$hotView);
    }
	
	public function getTopAnswer()
	{
		$sql = "select * from question order by answer_num desc limit 10";

		$hotAnswer = M()->query($sql);

		$this->assign('hotAnswer',$hotAnswer);
	}

	public function getTopUser()
	{
		$sql = "select * from user order by answer_num desc limit 12";

		$hotUser = M()->query($sql);

		$this->assign('hotUser',$hotUser);
	}

    



}

?>